package com.wontube.audio.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wontube.audio.pub.AppConfig;
import com.wontube.audio.pub.AudioCookieUtils;
import com.wontube.client.extension.utils.StringUtils;
import com.wontube.web.i18n.I18nMethod;

@Controller
@RequestMapping(value = "/mp3")
public class PopularMp3Controller {
	@RequestMapping(value = "/{mp3Name}")
	public ModelAndView showPopularMp3(HttpServletRequest request, @PathVariable("mp3Name") String mp3Name) {
		String localeName = AudioCookieUtils.getLocaleName(request);
		if(StringUtils.isNullOrEmpty(localeName)){
			localeName = "en_US";
		}
		Locale locale = AppConfig.getLocale(localeName);
		ModelAndView mv = getI18nView(locale);
		mv.setViewName("mp3/popular-mp3-detail");
		mv.addObject("mp3Name", mp3Name);
		mv.addObject("locale", localeName);
		
		return mv;
	}

	private ModelAndView getI18nView(Locale locale) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("i18n", new I18nMethod(AppConfig.widgetBundleName, locale));

		return mv;
	}
}
